package gb;

import gb.oper.PolyOp;
import gb.struct.Monomial;
import gb.struct.Polynomial;

public class SPoly {
    
    public static Polynomial compute(Polynomial f1, Polynomial f2) {
        Polynomial result = new Polynomial(f1.getComp());
        
        Monomial lm_f1 = f1.getMono(0);
        Monomial lm_f2 = f2.getMono(0);
        
        Monomial j = Utils.lcm(lm_f1, lm_f2);
        
        PolyOp op = new PolyOp();
        
        Monomial t1 = op.multiply(j, Utils.negatePow(lm_f1));
        Monomial t2 = op.multiply(j, Utils.negatePow(lm_f2));
        t2 = Utils.negateCoef(t2);
        result = op.add(op.multiply(t1, f1), op.multiply(t2, f2));
        
        return result;
    }

}
